package com.hbnu.system.controller;


import com.hbnu.system.core.base.CommonPage;
import com.hbnu.system.core.base.Rest;
import com.hbnu.system.model.dto.ArtDTO;
import com.hbnu.system.model.dto.CheckBackDTO;
import com.hbnu.system.model.entity.Art;
import com.hbnu.system.model.entity.Artfile;
import com.hbnu.system.model.query.ArtPageQuery;
import com.hbnu.system.model.vo.ArtVO;
import com.hbnu.system.service.IArtService;
import com.hbnu.system.service.IArtfileService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ${lei}
 * @since 2023-05-16
 */
@ApiOperation("艺术作品模块")
@RestController
@RequestMapping("/art")
@Api(tags = "艺术作品模块")
public class ArtController {

    @Autowired IArtService iArtService;

    @Autowired
    IArtfileService iArtfileService;

    @ApiOperation("艺术作品-正式录入")
    @PostMapping("/addArt")
    public Rest<Boolean> AddArt(@RequestBody Art art){
        boolean add = iArtService.addArt(art);
        return add ? Rest.success() : Rest.failed();
    }


    @ApiOperation("艺术作品-删除")
    @GetMapping("/DeleteArt")
    public Rest<Boolean> DeleteArt(String ArtID) throws IOException{
        boolean delete = iArtService.deleteArt(ArtID);
        return delete ? Rest.success() : Rest.failed();
    }

    @ApiOperation("艺术作品-修改")
    @PostMapping("/UpdateArt")
    public Rest<Boolean> UpdateArt(@RequestBody Art art){
        boolean update = iArtService.updateArt(art);
        return update ? Rest.success() : Rest.failed();
    }

    @ApiOperation("艺术作品-提交")
    @GetMapping("/ReCommitArt")
    public Rest<Boolean> ReCommitArt(String artID){
        boolean add = iArtService.ReCommitArt(artID);
        return add ? Rest.success() : Rest.failed();
    }
    
    @ApiOperation("艺术作品-撤回")
    @GetMapping("/WithdrawArt")
    public Rest<Boolean> WithdrawArt(String artID){
        boolean add = iArtService.withdrawArt(artID);
        return add ? Rest.success() : Rest.failed();
    }


    @ApiOperation("艺术作品-名称查重")
    @GetMapping("/CheckartName")
    public Rest<Boolean> CheckArtName(String artName){
        boolean check = iArtService.checkArtname(artName);
        return check ? Rest.success() : Rest.failed();
    }
    @ApiOperation("根据主键艺术作品查询")
    @GetMapping("/GetArtById")
    public Rest<Art> GetArtById(String artID){
        Art art = iArtService.getArt(artID);
        return Rest.success(art);
    }

    @ApiOperation("根据主键艺术DTO作品查询")
    @GetMapping("/GetArtDTOById")
    public Rest<ArtDTO> GetArtDTOById(String artID){
        ArtDTO artdto = iArtService.getArtDTOByID(artID);
        return Rest.success(artdto);
    }

    @ApiOperation("艺术作品-院级通过")
    @GetMapping("/CollegeCheckPass")
    public Rest<String> CollegePassArt(@RequestHeader("X-Token") String token,String AID){
        Boolean b = iArtService.collegeCheckPass(token,AID);
        return b ? Rest.success() : Rest.failed();
    }

    @ApiOperation("艺术作品-院级退回")
    @PostMapping("/CollegeCheckBack")
    public Rest<String> CollegeBackArt(@RequestHeader("X-Token") String token,@RequestBody CheckBackDTO checkBackDTO){
        Boolean b = iArtService.collegeCheckBack(token,checkBackDTO);
        return b ? Rest.success() : Rest.failed();
    }

    @ApiOperation("艺术作品-校级通过")
    @GetMapping("/SchoolCheckPass")
    public Rest<String> SchoolPassArt(@RequestHeader("X-Token") String token,String AID){
        Boolean b = iArtService.schoolCheckPass(token,AID);
        return b ? Rest.success() : Rest.failed();
    }

    @ApiOperation("艺术作品-校级退回")
    @PostMapping("/SchoolCheckBack")
    public Rest<String> SchoolBackArt(@RequestHeader("X-Token") String token,@RequestBody CheckBackDTO checkBackDTO){
        Boolean b = iArtService.schoolCheckBack(token,checkBackDTO);
        return b ? Rest.success() : Rest.failed();
    }

    @ApiOperation("用户获取与自己相关的艺术作品-分页")
    @PostMapping("/UserGetRelateArt")
    public Rest<CommonPage<ArtVO>> UserGetRelateArt(@RequestBody ArtPageQuery artPageQuery){
        CommonPage<ArtVO> artCommonPage =iArtService.userGetRelateArt(artPageQuery);
        return Rest.success(artCommonPage);
    }

    @ApiOperation("艺术作品-文件信息上传")
    @PostMapping("/addArtfile")
    public Rest<Boolean> addArtfile(@RequestBody Artfile art){
        boolean add = iArtfileService.addArtfile(art);
        return add ? Rest.success() : Rest.failed();
    }
    @ApiOperation("艺术作品-文件信息删除")
    @GetMapping("/DeleteArtfile")
    public Rest<Boolean> DeleteArtfile(String id) throws  IOException{
        boolean delete = iArtfileService.deletArtfile(id);
        return delete ? Rest.success() : Rest.failed();
    }
    @ApiOperation("艺术作品-文件信息分页查询")
    @GetMapping ("/pageArtfileCondition")
    public Rest<List<Artfile>> pageArtfileConditionfile(String id){
        List<Artfile> page = iArtfileService.pageArtfile(id);
        return Rest.success(page);
    }
    @ApiOperation("艺术作品-文件信息修改")
    @PostMapping("/updateArtfile")
    public Rest<Boolean> updateArtfile(@RequestBody Artfile Artfile){
        boolean update = iArtfileService.updateArtfile(Artfile);
        return update ? Rest.success() : Rest.failed();
    }


    /**
     * 下载数据库数据为exles
     *
     * @param
     * @throws IOException
     */
    @ApiOperation("艺体导出")
    @PostMapping("/export")
    public Rest<CommonPage<Art>> export(@RequestBody ArtPageQuery artPageQuery) {
        CommonPage<Art> artCommonPage = iArtService.export(artPageQuery);
        return Rest.success(artCommonPage);
    }
}

